//
//  HWRechargeVipHeadView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/14.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWRechargeVipHeadView.h"

@interface HWRechargeVipHeadView()
@property (nonatomic, strong)UILabel *nameLabel;// 名字
@property (nonatomic, strong)UIImageView *headImageView;//头像
@property (nonatomic, strong)UILabel *vipTimeLabel;//vip时间
@end

@implementation HWRechargeVipHeadView

- (UILabel *)nameLabel
{
    if (!_nameLabel)
    {
        _nameLabel = [HWUtilties creatLabelWithFrame:CGRectMake(16*kUIScaleBasePlus,29*kUIScaleBasePlus,0,21*kUIScaleBasePlus)
                                        textAligment:NSTextAlignmentLeft
                                            textClor:[UIColor blackColor]
                                            textFont:22*kUIScaleBasePlus];
    }
    return _nameLabel;
}

- (UIImageView *)headImageView
{
    if (!_headImageView)
    {
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width-20*kUIScaleBasePlus-37*kUIScaleBasePlus,30*kUIScaleBasePlus,37*kUIScaleBasePlus,37*kUIScaleBasePlus)];
        self.headImageView.layer.masksToBounds = YES;
        self.headImageView.layer.cornerRadius = _headImageView.frame.size.height/2;
    }
    return _headImageView;
}

- (UILabel *)vipTimeLabel
{
    if (!_vipTimeLabel)
    {
        _vipTimeLabel = [HWUtilties creatLabelWithFrame:CGRectMake(16*kUIScaleBasePlus,63*kUIScaleBasePlus,0,14*kUIScaleBasePlus)
                                           textAligment:NSTextAlignmentLeft
                                               textClor:LCHexColor(0x545454)
                                               textFont:14*kUIScaleBasePlus];
    }
    return _vipTimeLabel;
}
- (instancetype)initWithFrame:(CGRect)frame vipServiceArr:(NSArray *)arr
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addSubview:self.nameLabel];
        [self addSubview:self.headImageView];
        [self addSubview:self.vipTimeLabel];
        [self creatUI:arr];

    }
    return self;
}

- (void)creatUI:(NSArray *)arr
{
    CGFloat width = SCREEN_WIDTH/4;
    CGFloat height = 60*kUIScaleBasePlus;
    
    for (int i = 0;i < arr.count ; i++)
    {
        
        NSDictionary *dic = arr[i];
        
        UIButton *btn = [HWUtilties creatButtonWithFrame:CGRectMake(width*i,97*kUIScaleBasePlus,width,height)
                                            textAligment:NSTextAlignmentCenter
                                                    text:dic[@"title"]
                                                textClor:LCHexColor(0x4D4D4D)
                                               buttonBGC:[UIColor clearColor]
                                                textFont:10*kUIScaleBasePlus
                                                  target:self
                                                  method:nil];
//        btn.enabled = NO;
        [btn setImage:[UIImage imageNamed:dic[@"image"]] forState:UIControlStateNormal];
        [btn setUpImageAndDownLableWithSpace:5];
        
        [self addSubview:btn];
    }
}

- (void)getInfo:(HWRechargeVIPModel *)model
{
    self.nameLabel.text = model.nickName;
    [self.nameLabel sizeToFit];
    
    if ([model.isVip isEqualToString:@"1"])
    {
        self.vipTimeLabel.text = [NSString stringWithFormat:@"有效期:%@",model.vipDueTime];
        [self.vipTimeLabel sizeToFit];
    }
    else
    {
        self.vipTimeLabel.text = @"您还不是VIP，开通后可获得以下特权";
        [self.vipTimeLabel sizeToFit];
    }
    
    
    NSData *data = LCUserDefaultsGet(@"HeadView");
    if (data)
    {
        [self.headImageView setImage:[UIImage imageWithData:data]];
    }
    else
    {
        if ([model.headImg isEqualToString:@""])
        {
            [self.headImageView setImage:[UIImage imageNamed:@"head_normal"]];
        }
        else
        {
            [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headImg] placeholderImage:[UIImage imageNamed:@"head_normal"]];
        }
        
    }

}

@end
